<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
if(isset($_REQUEST["JO_action"]))
switch ($_REQUEST["JO_action"]){
    case "JO_addnewcomment":
        //include("../php_captcha/securimage.php");
        //$img = new Securimage();
        $valid = ($_SESSION["security_code"]==$_REQUEST['JO_capchari']?true:false);
        if($valid == true) {
            $_name=isset($_SESSION[ "JO_account_id" ])?"null":"'".JO_convertHTMLentities($_REQUEST["txtname"])."'";
            $_email=isset($_SESSION[ "JO_account_id" ])?"null":"'".JO_convertHTMLentities($_REQUEST["txtemail"])."'";
            $_content="'".JO_convertHTMLentities(str_replace("\r\n\t", "<br/>",$_REQUEST["JO_add_newcommenttxt"]))."'";
            $_roke=commentModule::addnewComment(
                   $_REQUEST["JO_article_key"],
                   isset($_SESSION[ "JO_account_id" ])?$_SESSION[ "JO_account_id" ]:"null",
                   $_name,
                   $_email,
                   $_content);
            if($_roke){
                echo "1";
            }else{
                echo "0";
            } 
        }else{
            echo "-1";
        }
        break;
}
class commentModule{
    public static  function addnewComment($_article,$_account,$_name,$_email,$_comment){
        $SQLCommand="call I_addnewcomment($_article,$_account,$_name,$_email,$_comment)";
        $n=DataProvider::executenoneSQL($SQLCommand);

        if($n==1)
                return true;
        return false;
    }
    public  static function getComments($_article){
        $SQLCommand="select * from getcomments where `delete` is null and article=".$_article;
        $data=DataProvider::executeSQL($SQLCommand);
        $dt=array();
        if($data->num_rows) while ($row=$data->fetch_array()){
                array_push($dt, $row);
        }else        return null;
        return $dt;
    }
}
?>